package com.cnnp.dip.present.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cnnp.dip.business.service.AnnotationService;

@RestController
@RequestMapping("/api/java/annotation")
public class AnnotationController {

    @Autowired
    private AnnotationService annotationService;

    @GetMapping
    public ResponseEntity<?> fetchAnnotations(
        @RequestParam(defaultValue = "100") int limit,
        @RequestParam(defaultValue = "false") boolean matchAny,
        @RequestParam String dashboardUID,
        @RequestParam int panelId
    ) {
        try {
            List<Map<String, Object>> data = annotationService.fetchAnnotations(limit, matchAny, dashboardUID, panelId);
            
            // 返回结果
            Map<String, Object> response = new HashMap<>();
            response.put("data", data);
            
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body(Map.of("error", "Failed to fetch annotations", "detail", e.getMessage()));
        }
    }
}